package com.jinglin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.jinglin.entity.po.UserFocus;
import com.jinglin.entity.query.SimplePage;
import com.jinglin.entity.vo.PaginationResultVO;
import com.jinglin.mapper.UserFocusMapper;
import com.jinglin.service.UserFocusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * focus_user_id是被关注的人。	user_id是发起关注的人。 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2025-03-29
 */
@Service
public class UserFocusServiceImpl extends ServiceImpl<UserFocusMapper, UserFocus> implements UserFocusService {
    @Autowired
    private UserFocusMapper userFocusMapper;
    @Override
    public PaginationResultVO getFocusList(String userId, Integer pageNo, Integer pageSize) {
        List<UserFocus> focusList = userFocusMapper.getFocusList(userId, pageNo - 1, pageSize);

        Integer count = getFocusCount(userId);

        /*
        * 由于我这里没有按照开发者自己设定的page框架，因此我需要这么手动转换一下page对象
        * */
        SimplePage page = new SimplePage(pageNo, count, pageSize);
        PaginationResultVO<UserFocus> resultVO = new PaginationResultVO<>(count, pageSize, pageNo,page.getPageTotal(), focusList);
        return resultVO;
    }

    @Override
    public PaginationResultVO getFansList(String userId, Integer pageNo, Integer pageSize) {
        List<UserFocus> focusList = userFocusMapper.getFansList(userId, pageNo - 1, pageSize);
        Integer count = getFansCount(userId);

        SimplePage page = new SimplePage(pageNo, count, pageSize);
        PaginationResultVO<UserFocus> resultVO = new PaginationResultVO<>(count, pageSize, pageNo,page.getPageTotal(), focusList);
        return resultVO;
    }

    @Override
    public Integer getFansCount(String userId) {
        LambdaQueryWrapper<UserFocus> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserFocus::getFocusUserId,userId);
        int count = this.count(wrapper);
        return count;
    }

    @Override
    public Integer getFocusCount(String userId) {
        LambdaQueryWrapper<UserFocus> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserFocus::getUserId,userId);
        int count = this.count(wrapper);
        return count;
    }


}
